package com.zzf.concurrent.example.design.pattern.future;

import java.util.function.Consumer;

/**
 * @author GaoFeng2017
 * @date 2019/9/7 20:22
 */
public class FutureService<T> {

    public Future<T>  submit(FutureTask<T> task, Consumer<T> consumer) {
        AsyncFuture<T> future = new AsyncFuture<>();
        new Thread(() -> {
            T result = task.call();
            future.done(result);
            consumer.accept(result);
        }).start();

        return future;
    }

}
